package com.sure.minion.services.base.handler.exception;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.validation.ConstraintViolation;

import com.sure.minion.services.base.vo.ValidateMsgVO;

/**
 * @Description 验证自定义异常
 * @author syuan
 * @date 2015年2月6日 下午7:29:11 Company: TravelSky
 */
public class ValidateAutoHandledException extends DefaultAutoHandledException {

	private static final long serialVersionUID = 392637512807577200L;

	/**
	 * @Fields description 错误代码
	 * @author syuan
	 * @date 2015年2月9日 下午6:37:11
	 */
	private String description;

	public <T> ValidateAutoHandledException(String description,
			Set<ConstraintViolation<T>> violations) {
		this.description = description;
		//错误信息封装
		List<ValidateMsgVO> msgs = new ArrayList<ValidateMsgVO>();
		for (ConstraintViolation<T> violation : violations) {
			msgs.add(new ValidateMsgVO(violation.getPropertyPath().toString(),
					violation.getMessage(), violation.getInvalidValue()));
		}
		this.responseObject = msgs;
	}

	public  ValidateAutoHandledException(String description,
			ValidateMsgVO validateMsgVO) {
		this.description = description;
		//错误信息封装
		List<ValidateMsgVO> msgs = new ArrayList<ValidateMsgVO>();
		msgs.add(validateMsgVO);
		this.responseObject = msgs;
	}
	
	public String getDescription() {
		return description;
	}

}
